package com.ruoyi.app.controller

import com.ruoyi.app.common.Data
import com.ruoyi.app.common.PageData
import com.ruoyi.app.domain.dto.*
import com.ruoyi.app.domain.vo.*
import com.ruoyi.app.service.TemplateApiService
import io.swagger.annotations.Api
import io.swagger.annotations.ApiImplicitParam
import io.swagger.annotations.ApiImplicitParams
import io.swagger.annotations.ApiOperation
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.*

@RestController
@RequestMapping("api/template")
@Api(tags = ["模板相关接口"])
class TemplateApiController {

    @Autowired
    private lateinit var templateApiService: TemplateApiService


    @ApiOperation("模板页数据")
    @GetMapping("templatePage")
    fun templatePage(appTemplateSearchDto: AppTemplateSearchDto): Data<TemplateIndex> = templateApiService.templatePage(appTemplateSearchDto)

    @ApiOperation("模板详情")
    @GetMapping("templateDetail/{id}")
    @ApiImplicitParams(
        ApiImplicitParam(
            name = "id",
            value = "模板id",
            type = "path",
            required = true
        )
    )
    fun templateDetail(@PathVariable id: Long): Data<TemplateDetailVo> = templateApiService.templateDetail(id)

    @ApiOperation("模板点赞")
    @PostMapping("templateLike/{id}")
    @ApiImplicitParams(
        ApiImplicitParam(
            name = "id",
            value = "模板id",
            type = "path",
            required = true
        )
    )
    fun templateLike(@PathVariable id: Long): Data<Boolean> = templateApiService.templateLike(id)

    @ApiOperation("模板收藏")
    @PostMapping("templateCollect/{id}")
    @ApiImplicitParams(
        ApiImplicitParam(
            name = "id",
            value = "模板id",
            type = "path",
            required = true
        )
    )
    fun templateCollect(@PathVariable id: Long): Data<Boolean> = templateApiService.templateCollect(id)


    @ApiOperation("模板评论")
    @PostMapping("templateComment")
    fun templateComment(appTemplateCommentDto: AppTemplateCommentDto): Data<Boolean> =
        templateApiService.templateComment(appTemplateCommentDto)

    @ApiOperation("模板评论列表")
    @GetMapping("templateCommentPage")
    fun templateCommentPage(templateCommentSearchDto: AppTemplateCommentSearchDto): PageData<AppTemplateCommentVo> =
        templateApiService.templateCommentPage(templateCommentSearchDto)

    @ApiOperation("模板举报")
    @PostMapping("templateReport")
    fun templateReport(appTemplateReportDto: AppTemplateReportDto): Data<Boolean> =
        templateApiService.templateReport(appTemplateReportDto)


    @ApiOperation("模板推荐记录数据")
    @GetMapping("templateRecommendData")
    fun templateRecommendData(userRecommendSearchDto: UserRecommendSearchDto): Data<List<StatusType>> =
        templateApiService.templateRecommendData(userRecommendSearchDto)

    @ApiOperation("移除模板推荐")
    @GetMapping("removeTemplateRecommend/{ids}")
    @ApiImplicitParams(
        ApiImplicitParam(
            name = "ids",
            value = "多个id用逗号拼接",
            type = "path",
            required = true
        )
    )
    fun removeTemplateRecommend(@PathVariable ids: String): Data<Boolean> =  templateApiService.removeTemplateRecommend(ids)

    @ApiOperation("我的收藏")
    @PostMapping("myCollectPage")
    fun myCollectPage(templateSearchDto: AppTemplateSearchDto): Data<PageData<TemplateListVo>> =
        templateApiService.myCollectPage(templateSearchDto)
}